{extend name="base" /}
{block name="header"}
<div class="admin_header_{$skin_name|default='default'} clearfix">
    <div class="title"><i></i>{$title|default=""}</div>
    <div class="action">
        <b></b>
        <div class="layui-btn-group layui-btn-group-only">
            <a class="layui-btn  layui-btn-disabled layui-btn-sm "><i class="fa fa-reply"></i> 返 回 </a>
        </div>
    </div>
</div>
{/block}
{block name="main"}
<div class="box_form">

    <div class="box_content">
        <form class="layui-form" id="admin">
            <input type="hidden" name="token" value="{$token}" />
            <div class="layui-form-item">
                <label class="layui-form-label">旧密码</label>
                <div class="layui-input-inline">
                    <input id="password_old" name="password_old" lay-verify="pass" placeholder="请输入旧密码" autocomplete="off" class="layui-input" type="password">
                </div>
                <div class="layui-form-mid layui-word-aux">请填写6到12位密码</div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">新密码</label>
                <div class="layui-input-inline">
                    <input id="password_new" name="password_new" lay-verify="pass" placeholder="请输入新密码" autocomplete="off" class="layui-input" type="password">
                </div>
                <div class="layui-form-mid layui-word-aux">请填写6到12位密码</div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">重复新密码</label>
                <div class="layui-input-inline">
                    <input id="password_confirm" name="password_confirm" lay-verify="pass" placeholder="请再次输入新密码" autocomplete="off" class="layui-input" type="password">
                </div>
            </div>

            <input type="hidden" name="id" value="{$id}">

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn and-bg-{$skin_name|default='default'}" lay-submit lay-filter="admin">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>

        </form>

    </div>
</div>
{/block}

{block name="script"}

<script>
    layui.use(['layer', 'form'], function() {
        var layer = layui.layer,
                $ = layui.jquery,
                form = layui.form;
        form.verify({
            pass: [
                /^[\S]{6,12}$/
                ,'密码必须6到12位，且不能出现空格'
            ]
        });
        $(window).on('load', function() {
            form.on('submit(admin)', function(data) {
                layer.closeAll();
                var password_old = $.trim($('#password_old').val());
                if (!password_old) {
                    layer.msg('请填写旧密码',{
                        anim: 1,
                        offset: '200px'
                    });
                    return false;
                }
                var password_new = $.trim($('#password_new').val());
                if (!password_new) {
                    layer.msg('请填写新密码',{
                        anim: 1,
                        offset: '200px'
                    });
                    return false;
                }
                var password_confirm = $.trim($('#password_confirm').val());
                if (password_confirm != password_new) {
                    layer.msg('两次密码不一致哦',{
                        anim: 1,
                        offset: '200px'
                    });
                    return false;
                }
                $.ajax({
                    url:"{:url('admin/adminUser/update_password')}",
                    data:$('#admin').serialize(),
                    type:'post',
                    async: false,
                    success:function(res) {
                        if(res.code == 1) {
                            layer.alert(res.msg, function(index){
//                                parent.location.reload();
                                location.href = res.url;
                            })
                        } else {
                            layer.msg(res.msg);
                        }
                    }
                });
                return false;
            });
        });
    });
</script>
{/block}